package com.smedi.ismedi.inmail.core.port.adapter.persistence.repository.impl;

import com.smedi.ismedi.file.dto.response.FileInfoResponse;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Attachment;
import com.smedi.ismedi.inmail.core.domain.dto.AttachmentQuery;
import com.smedi.ismedi.inmail.core.domain.repository.AttachmentRepository;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.inmail.core.port.adapter.service.FileRemoteApi;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 主体院关系实现类
 *
 * @author niuyanling
 * @date 2021/08/05
 */
@Repository
@RequiredArgsConstructor
public class AttachmentRepositoryImpl implements AttachmentRepository {
    private final AdapterConverter adapterConverter;

    private final FileRemoteApi fileRemoteApi;

    @Override
    public Attachment getAttachmentOne(AttachmentQuery attachmentQuery) {
        FileInfoResponse file = fileRemoteApi.getFileOne(attachmentQuery);
        return adapterConverter.fileInfoResponseToAttachment(file);
    }

    @Override
    public List<Attachment> getAttachmentList(AttachmentQuery attachmentQuery) {
        List<FileInfoResponse> files = fileRemoteApi.getFileList(attachmentQuery);
        return adapterConverter.fileInfoResponseToAttachment(files);
    }

    @Override
    public List<Attachment> getAttachmentListByPost(AttachmentQuery attachmentQuery) {
        List<FileInfoResponse> files = fileRemoteApi.getFileListByPost(attachmentQuery);
        return adapterConverter.fileInfoResponseToAttachment(files);
    }
}
